package ldh.im.fxgui.component;

import javafx.scene.Cursor;
import javafx.scene.paint.Color;
import ldh.im.fxbase.util.IconUtil;
import org.controlsfx.control.textfield.CustomTextField;
import org.kordamp.ikonli.javafx.FontIcon;

public class SearchTextField extends CustomTextField {

    public SearchTextField() {
        initUi();
    }

    private void initUi() {
        FontIcon closeIcon = IconUtil.createIcon("fa-close", 8, Color.BLACK);
        closeIcon.setOnMouseClicked(e->{
            this.setText("");
        });
        closeIcon.setOnMouseEntered(e->closeIcon.setCursor(Cursor.HAND));
        closeIcon.setVisible(false);
        this.rightProperty().set(closeIcon);
        this.textProperty().addListener(l->{
            if (getText().length() > 0) {
                closeIcon.setVisible(true);
            }
        });

        FontIcon searchIcon = IconUtil.createIcon("fa-search", 8, Color.BLACK);
        this.leftProperty().set(searchIcon);
    }
}
